package io.renren.modules.store.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.renren.common.utils.R;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.store.dao.TTableThemeDao;
import io.renren.modules.store.entity.TTableThemeEntity;
import io.renren.modules.store.service.TTableThemeService;


@Service("tTableThemeService")
public class TTableThemeServiceImpl extends ServiceImpl<TTableThemeDao, TTableThemeEntity> implements TTableThemeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TTableThemeEntity> page = this.page(
                new Query<TTableThemeEntity>().getPage(params),
                new QueryWrapper<TTableThemeEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public TTableThemeEntity queryTheme(Long seller) {
        TTableThemeEntity themeEntity = null;
        themeEntity = getOne(
                new LambdaQueryWrapper<TTableThemeEntity>()
                        .eq(TTableThemeEntity::getSellerId, seller)
        );
        //商户没有配置餐台主题，则默认使用系统自带主题
        if (themeEntity == null){
            themeEntity = getOne(
                    new LambdaQueryWrapper<TTableThemeEntity>()
                            .eq(TTableThemeEntity::getSellerId, "-1")
            );
        }
        return themeEntity;
    }

}